package tommysmapeditor.editors;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.PaintEvent;
import org.eclipse.swt.events.PaintListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Transform;
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.EditorPart;

public class ScaleTest extends EditorPart {

	Image image;
	
	public ScaleTest() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void doSave(IProgressMonitor monitor) {
		// TODO Auto-generated method stub

	}

	@Override
	public void doSaveAs() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init(IEditorSite site, IEditorInput input)
			throws PartInitException {
setSite(site);
setInput(input);
	}

	@Override
	public boolean isDirty() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isSaveAsAllowed() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public void createPartControl(Composite parent) {
		image = new Image(Display.getCurrent(),"tile0.bmp");
		
		Canvas canvas = new Canvas(parent,SWT.NONE);
		canvas.addPaintListener(
				new PaintListener(){

					public void paintControl(PaintEvent e) {
						
						Transform scale = new Transform(Display.getCurrent());
						scale.scale(10, 10);
						e.gc.setTransform(scale);
						
						e.gc.drawImage(image, 0, 0);
						
						
						scale.dispose();
					}
					
				}
		);
	}

	@Override
	public void setFocus() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		super.dispose();
		image.dispose();
	}
	
	
}
